<?php

class Repplied_mgr extends CI_Model {

    function __Construct() {
        parent::__Construct();
    }

    function allreplied($limit, $start) {
        $this->db->limit($limit, $start);
        $this->db->select('*');
        $this->db->from('tbl_replies');
        $this->db->join('tbl_role', 'tbl_replies.rep_author=tbl_role.role_id');
        $this->db->join('tbl_replies', 'tbl_threads.thread_id=tbl_replies.thread_id');
        
		return $this->db->get();
    }

	
	//from below is yet use
    function delete_users($data) {
        $this->db->delete('user', $data);
    }

    //edit function
    function select_edit_user() {
        $id = $this->uri->segment('4');
        $this->db->select('*');
        $this->db->from('user');
        $this->db->join('tbl_role', 'user.role_id=tbl_role.role_id');
        $this->db->where('id', $id);

        return $this->db->get();
    }

    //update user here
    function update_user() {
        $this->load->library("form_validation");
        $query_str = array(
            'firstName' => $this->input->post('fname'),
            'lastName' => $this->input->post('lname'),
            'user_name' => $this->input->post('username'),
            'password' => md5($this->input->post('pass')),
            'user_gender' => $this->input->post('gender'),
            'email' => $this->input->post('email'),
            'user_nationality' => $this->input->post('nation'),
            'user_add' => $this->input->post('address'),
            'role_id' => $this->input->post('role')
        );
        $id = $this->input->post('getid');
        $this->db->where('id', $id);
        return $this->db->update('user', $query_str);
    }

    function checkexist($username) {
        $qu = "SELECT user_name FROM user WHERE user_name = ? ";
        $result = $this->db->query($qu, $username);
        if ($result->num_rows() > 0) {
            return true;
        } else {
            return false;
        }
    }

    function addnewthread() {
        $this->load->library("form_validation");

        $query_str = array(
            'thread_title' => $this->input->post('th_title'),
            'thread_content' => $this->input->post('th_content'),
            'thread_dated' => $this->input->post('th_dated'),
            'thread_author' => $this->input->post('th_author'),
            'thread_status' => $this->input->post('th_status')
        );

        return $this->db->insert('tbl_threads', $query_str);
    }

    function deletethread($data) {
        $this->db->delete('tbl_threads', $data);
    }

    //edit function
    function thread_select_edit() {
        $id = $this->uri->segment('3');
        $this->db->select('*');
        $this->db->from('tbl_threads');
        $this->db->join('tbl_role', 'tbl_threads.thread_author=tbl_role.role_id');
        $this->db->where('thread_id', $id);

        return $this->db->get();
    }

    //update there here
    function update_thread() {
        $this->load->library("form_validation");
        $query_str = array(
            'thread_title' => $this->input->post('title'),
            'thread_content' => $this->input->post('content'),
            'thread_dated' => $this->input->post('dated'),
            'thread_author' => $this->input->post('author'),
            'thread_status' => $this->input->post('status')
        );
        $id = $this->input->post('getid');
        $this->db->where('thread_id', $id);

        return $this->db->update('tbl_threads', $query_str);
    }

}